package com.it.service.impl;

import com.it.common.Result;
import com.it.dao.SongMapper;
import com.it.domain.Song;
import com.it.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SongServImpl implements SongService {

    @Autowired
    private SongMapper songMapper;

    @Override
    public Object AddSong(Song song) {
        Song song1 = songMapper.SelectBySong(song.getName().trim(),song.getAlbum().trim(),song.getSingerId());
        System.out.println(song1);
        if(song1 != null){
            return Result.fail("405","歌曲已存在");
        }
        else{
            if(songMapper.AddSong(song)>0){

                return Result.success("200","添加成功");
            }
            else{
                return Result.fail("406","添加失败");

            }
        }
    }

    @Override
    public boolean UpdateSong(Song song) {
        return songMapper.UpdateSong(song)>0;
    }

    @Override
    public boolean DeleteSong(Integer id) {
        return songMapper.DeleteSong(id)>0;
    }

    @Override
    public Song SelectBySongId(Integer id) {
        return songMapper.SelectBySongId(id);
    }

    @Override
    public List<Song> SelectBySingerId(Integer singerId) {
        return songMapper.SelectBySingerId(singerId);
    }

    @Override
    public List<Song> SelectByName(String name) {
        return songMapper.SelectByName(name);
    }

    @Override
    public List<Song> SelectAll(Integer PageNum, Integer PageSize,Integer singerId,String name) {
        return songMapper.SelectAll(PageNum,PageSize,singerId,name);
    }

    @Override
    public Integer SelectTotal() {
        return songMapper.SelectTotal();
    }

    @Override
    public Integer SelectSingerSongTotal(Integer singerId) {
        return songMapper.SelectSingerSongTotal(singerId);
    }

    @Override
    public List<Song> GetAllSong() {
        return songMapper.GetAllSong();
    }

    @Override
    public Integer UpdateType(Integer id, Integer isDelete) {
        return songMapper.UpdateType(id,isDelete);
    }

    @Override
    public Integer getSongsTotal(Integer singerId) {
        return songMapper.getSongsTotal(singerId);
    }

    @Override
    public Integer getAlbumTotal(Integer singerId) {
        return songMapper.getAlbumTotal(singerId);
    }

    @Override
    public List<Song> getSongInfo(Integer singerId) {
        return songMapper.getSongInfo(singerId);
    }
}
